// 声明所有接口的请求地址,具体用途参考函数install
import request from './requesr'
const loginUrl = '/api/login'
const getClockUrl = '/api/getClock'
const getNoticeUrl = '/api/getNotice'
const downloadUrl = '/api/uploads/apk'
const getFileDownUrl = '/api/getFileDown'
const updatePasswordUrl = '/api/updatePassword'
const getImagesUploadUrl = '/api/getImagesUpload'
const getFileVersionsUrl = '/api/getFileVersions'
const getCalendarClockUrl = '/api/getCalendarClock'
const getDeteleUploadUrl = '/api/getDeteleUploadApp'

const install = (Vue, vm) => {
  // params参数为请求时传入的data,也可附加第二个参数,第三个参数...用于其他特殊处理
  // 登录
  const login = (data) => {
    return request({
      url: loginUrl,
      method: 'post',
      data: data
    })
  }

  // 修改密码
  const updatePassword = (data) => {
    return request({
      url: updatePasswordUrl,
      method: 'post',
      data: data
    })
  }

  // 通知
  const getNotice = (params) => {
    return request({
      url: getNoticeUrl,
      method: 'get',
      params: params
    })
  }

  // 首页日历
  const getClock = (params) => {
    return request({
      url: getClockUrl,
      method: 'get',
      params: params
    })
  }

  // 首页打卡
  const getCalendarClock = (data) => {
    return request({
      url: getCalendarClockUrl,
      method: 'post',
      data: data
    })
  }

  // 获取版本信息
  const getFileVersions = (params) => {
    return request({
      url: getFileVersionsUrl,
      method: 'get',
      params: params
    })
  }

  // 获取版本信息
  const getFileDown = (params) => {
    return request({
      url: getFileDownUrl,
      method: 'get',
      params: params
    })
  }

  // 下载版本文件
  const download = (params) => {
    return request({
      url: downloadUrl,
      method: 'get',
      params: params
    })
  }

  // 获取图片
  const getImagesUpload = (params) => {
    return request({
      url: getImagesUploadUrl,
      method: 'get',
      params: params
    })
  }

  // 删除图片
  const getDeteleUpload = (data) => {
    return request({
      url: getDeteleUploadUrl,
      method: 'post',
      data: data
    })
  }

  // 将各个定义的接口名称，统一放进对象挂载到vm.$u.api(因为vm就是this，也即this.$u.api)下
  vm.$u.api = {
    login,
    getClock,
    getNotice,
    download,
    updatePassword,
    getImagesUpload,
    getCalendarClock,
    getDeteleUpload,
    getFileVersions,
    getFileDown
  }
}

// 导出install函数
export default {
  install
}
